/***************************************************************************
 *   Copyright (C) 2010 by Oleg Goncharov  *
 *   $EMAIL$                           *                          
 *                                                                         *
 *   This file is part of ChessVision.                                     *
 *                                                                         *
 *   ChessVision is free software; you can redistribute it and/or modify   *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
#ifndef GEOMTYPES_H
#define GEOMTYPES_H

#include <opencv/cxcore.h>
#include <vector>
#include <ostream>

typedef cv::Point3f Point3f;
typedef cv::Point3d Point3d;
typedef cv::Point2f Point2f;
typedef std::vector<cv::Point3d> Path3D;

std::ostream& operator<<(std::ostream& out, const cv::Point3f& p); 
std::ostream& operator<<(std::ostream& out, const cv::Point2f& p);

struct HPlane3f {
	float A, B, C, D;
	HPlane3f() {}
	HPlane3f(const HPlane3f& p) { A = p.A; B = p.B; C = p.C; D = p.D; }
	HPlane3f(float a, float b, float c, float d) : A(a), B(b), C(c), D(d) {}
};

struct Line2f {
	float teta, r;
	
	Line2f() {}
	Line2f(float _r, float _teta) : teta(_teta), r(_r) {} 
	Line2f(const Line2f& line) : teta(line.teta), r(line.r) {} 
	
	bool Intersect(const Line2f& line, cv::Point2f& point) const;
	//cv::Point2f Intersect(const Line2f& line);
};



struct SRectF {
	float x1, x2, y1, y2;
	
	SRectF() {}
	SRectF(float _x1, float _y1, float _x2, float _y2) : x1(_x1), x2(_x2), y1(_y1), y2(_y2) {}
	bool Contains(float x, float y) const {
		return x <= x2 && x >= x1 && y <= y2 && y >= y1;
	}
};

struct SRect {
	int x1, x2, y1, y2;
	
	SRect() {}
	SRect(const CvRect& r) : x1(r.x), x2(r.x+r.width), y1(r.y), y2(r.y+r.height) {}
	SRect(int _x1, int _y1, int _x2, int _y2) : x1(_x1), x2(_x2), y1(_y1), y2(_y2) {}
	bool Contains(int x, int y) const {
		return x <= x2 && x >= x1 && y <= y2 && y >= y1;
	}
	bool Overlap(const SRect& r) const {
		return (r.x2 - x1)*(r.x1 - x2) < 0 && (r.y2 - y1)*(r.y1 - y2) < 0;
	}
	bool IsInside(const SRect& r) const {
		return x1 >= r.x1 && y1 >= r.y1 && x2 <= r.x2 && y2 <= r.y2;
	}
};

#endif

